﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AppraisalManagement.utils;

namespace AppraisalManagement
{
    public partial class evaluation : System.Web.UI.Page
    {
        protected EmpKPILinkingDataSet.Employee_KPI_MarksDataTable marksDt = new EmpKPILinkingDataSet.Employee_KPI_MarksDataTable();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            int empPk = 0;
            Hierarchy mastr = (Hierarchy)this.Master;

            Session[ApplicationConstants.SELECTED_PK.ToString()] = mastr.hierarchyTree.SelectedValue;

            Int32.TryParse(Session[ApplicationConstants.SELECTED_PK.ToString()].ToString(), out empPk);
            marksDt = new EmpKPILinkingDataSetTableAdapters.Employee_KPI_MarksTableAdapter().GetData(empPk);
            if (!IsPostBack)
            {
                txtMarks.Text = "0";
            }
        }

        protected void submitEvaluation_Click(object sender, EventArgs e)
        {
           
            String name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;


           String[] marksStrs = txtMarks.Text.Split(new String[] { "," }, StringSplitOptions.None);

            EmpKPILinkingDataSetTableAdapters.Employee_KPI_MarksTableAdapter marksAdp = new EmpKPILinkingDataSetTableAdapters.Employee_KPI_MarksTableAdapter();

            Decimal[] marks = new Decimal[marksStrs.Length];

            try
            {
                for (int loop = 0; loop < marksStrs.Length; loop++)
                {
                    marks[loop] = Decimal.Parse(marksStrs[loop].Trim());
                }
            }
            catch (Exception e1)
            {
                ((Hierarchy)this.Master).message = "Invalid Marks entered";
                return;
            }

            int loop1 = 0;
            foreach (EmpKPILinkingDataSet.Employee_KPI_MarksRow marksR in marksDt.Rows)
            {
                marksAdp.InsertMarks(marksR.emp_kpi_pk, marks[loop1]);
                loop1 += 1;
            }
            txtMarks.Text = "0";
             ((Hierarchy) this.Master).isSuccessfull = true;

             Response.Redirect("displayEvaluation.aspx");
        }
    }
}
